import { SETMOCKLIST } from "./action-type";
import { handleActions } from "redux-actions";
const initialState = {
  mockList: [],
  status: "false",
};

export function setmocklist(params) {
  return (dispatch, _, { get }) => {
    dispatch({ type: SETMOCKLIST, payload: { status: "loading" } });
    new Promise((reslove, reject) => {
      get("/api/mock/easyData", {})
        .then((res) => {
          console.log(res);
          reslove(res);
          dispatch({
            type: SETMOCKLIST,
            payload: { mockList: [...res], status: "success" },
          });
        })
        .catch((err) => {
          reject(err);
          dispatch({
            type: SETMOCKLIST,
            payload: { status: "fail" },
          });
        });
    });
  };
}
export default handleActions(
  {
    [SETMOCKLIST](state, { type, payload }) {
      console.log(payload);
      return { ...state, ...payload };
    },
  },
  initialState
);
// export default (state = initialState, { type, payload }) => {
//   switch (type) {
//     case "SETMOCKLIST":
//       return { ...state, ...payload };

//     default:
//       return state;
//   }
// };
